#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
int gd=DETECT,gm,i,m,c,x1,y1,x2,y2,x_new,y_new,Ax,Ay,Bx,By;
initgraph(&gd,&gm,"C:\\Turboc3\\BGI");
moveto(0,50);
rectangle(0,50,200,200);
moveto(100,100);
lineto(150,350);
Ax=100;Ay=100;
Bx=150;By=350;
if((Ax>=0 && Ax<=200) && (Ay>=50 && Ay<=200) && (Bx>=0 && Bx<=200) && (By>=50 && By<=200))
{
   printf("Line is totally visible\n");
}
else
{
printf("Line is partially visible\n");
}
printf("Before clipping\n");
printf("press 1\n");
scanf("%d",&i);
if(i==1)
{
cleardevice();
printf("After clipping");
moveto(0,50);
rectangle(0,50,200,200);
x1=100;y1=100;
x2=150;y2=350;
y_new=200;
m=(y2-y1)/(x2-x1);
c=y2-(m*x2);
x_new=(y_new-c)/m;
moveto(x1,y1);
lineto(x_new,y_new);
}
getch();
closegraph();
}